package com.morehair.service.admin.impl;

import com.morehair.bean.pojo.Config;
import com.morehair.bean.pojo.ConfigExample;
import com.morehair.bean.vo.admin.ConfigMallVo;
import com.morehair.bean.vo.admin.ExpressVo;
import com.morehair.bean.vo.admin.OrderVo;
import com.morehair.bean.vo.admin.WxVo;
import com.morehair.mapper.ConfigMapper;
import com.morehair.service.admin.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;

/**
 * Description:
 * Date: 2021/6/7
 * Time: 21:58
 * author: zhang wei
 */

@Service
@Transactional
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    ConfigMapper configMapper;


    @Override
    public ConfigMallVo queryConfigMall() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(38);
        list.add(40);
        list.add(44);
        list.add(46);
        ConfigExample configExample = new ConfigExample();
        ConfigExample.Criteria criteria = configExample.createCriteria();
        criteria.andIdIn(list);
        List<Config> configs = configMapper.selectByExample(configExample);
        return new ConfigMallVo(configs.get(0).getKeyValue(),
                                configs.get(1).getKeyValue(),
                                configs.get(2).getKeyValue(),
                                configs.get(3).getKeyValue());
    }

    @Override
    public void updateConfigMall(ConfigMallVo configMallVo) {
        Config config1 = new Config();
        config1.setId(38);
        config1.setKeyValue(configMallVo.getCskaoyanmall_mall_name());
        configMapper.updateByPrimaryKeySelective(config1);

        Config config2 = new Config();
        config2.setId(40);
        config2.setKeyValue(configMallVo.getCskaoyanmall_mall_qq());
        configMapper.updateByPrimaryKeySelective(config2);

        Config config3 = new Config();
        config3.setId(44);
        config3.setKeyValue(configMallVo.getCskaoyanmall_mall_phone());
        configMapper.updateByPrimaryKeySelective(config3);

        Config config4 = new Config();
        config4.setId(46);
        config4.setKeyValue(configMallVo.getCskaoyanmall_mall_address());
        configMapper.updateByPrimaryKeySelective(config4);
    }

    @Override
    public ExpressVo queryExpress() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(37);
        list.add(39);
        ConfigExample configExample = new ConfigExample();
        ConfigExample.Criteria criteria = configExample.createCriteria();
        criteria.andIdIn(list);
        List<Config> configs = configMapper.selectByExample(configExample);
        ExpressVo expressVo = new ExpressVo(configs.get(1).getKeyValue(), configs.get(0).getKeyValue());
        return expressVo;
    }

    @Override
    public void updateExpress(ExpressVo expressVo) {
        Config config1 = new Config();
        config1.setId(37);
        config1.setKeyValue(expressVo.getCskaoyanmall_express_freight_min());
        configMapper.updateByPrimaryKeySelective(config1);

        Config config2 = new Config();
        config2.setId(39);
        config2.setKeyValue(expressVo.getCskaoyanmall_express_freight_value());
        configMapper.updateByPrimaryKeySelective(config2);
    }

    @Override
    public OrderVo queryOrder() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(33);
        list.add(35);
        list.add(42);
        ConfigExample configExample = new ConfigExample();
        ConfigExample.Criteria criteria = configExample.createCriteria();
        criteria.andIdIn(list);
        List<Config> configs = configMapper.selectByExample(configExample);
        OrderVo orderVo = new OrderVo(configs.get(0).getKeyValue(), configs.get(1).getKeyValue(), configs.get(2).getKeyValue());
        return orderVo;
    }

    @Override
    public void updateOrder(OrderVo orderVo) {
        Config config1 = new Config();
        config1.setId(33);
        config1.setKeyValue(orderVo.getCskaoyanmall_order_unpaid());
        configMapper.updateByPrimaryKeySelective(config1);

        Config config2 = new Config();
        config2.setId(35);
        config2.setKeyValue(orderVo.getCskaoyanmall_order_unconfirm());
        configMapper.updateByPrimaryKeySelective(config2);

        Config config3 = new Config();
        config3.setId(42);
        config3.setKeyValue(orderVo.getCskaoyanmall_order_comment());
        configMapper.updateByPrimaryKeySelective(config3);


    }

    @Override
    public WxVo queryWx() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(34);
        list.add(36);
        list.add(41);
        list.add(43);
        list.add(45);
        list.add(47);
        list.add(48);
        ConfigExample configExample = new ConfigExample();
        ConfigExample.Criteria criteria = configExample.createCriteria();
        criteria.andIdIn(list);
        List<Config> configs = configMapper.selectByExample(configExample);
        WxVo wxVo = new WxVo(configs.get(0).getKeyValue(),
                            configs.get(1).getKeyValue(),
                            configs.get(2).getKeyValue(),
                            configs.get(3).getKeyValue(),
                            configs.get(4).getKeyValue(),
                            configs.get(5).getKeyValue(),
                            configs.get(6).getKeyValue());
        return wxVo;
    }

    @Override
    public void updateTx(WxVo wxVo) {
        Config config = new Config();
        config.setId(34);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_index_new());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(36);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_share());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(41);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_index_hot());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(43);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_catlog_goods());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(45);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_catlog_list());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(47);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_index_brand());
        configMapper.updateByPrimaryKeySelective(config);

        config.setId(48);
        config.setKeyValue(wxVo.getCskaoyanmall_wx_index_topic());
        configMapper.updateByPrimaryKeySelective(config);
    }


}
